new Vue({
  el: '#container',
  data: {
    mediaReportList: [],
    lastId: 0,
    rendered: false,
    page: {
      pageSize: 10,
      hasNextPage: false
    }
  },

  created: function() {
    this.getMediaReportList();
  },
  mounted: function() {},

  methods: {
    getMediaReportList: function() {
      var mediaReportList = this.mediaReportList,
        that = this,
        lastId = mediaReportList.length ? mediaReportList[mediaReportList.length - 1].id : '';
      if (lastId === this.lastId) {
        return;
      }
      $.ajax({
        // ?imageView2/0/interlace/1/q/75
        url: window.HOST_NAME + 'mediaArticle/list',
        // url: "http://testabc.ultimablack.cn/seoNews/list",
        // url: window.HOST_NAME + "seoNews/list",
        data: {
          pageSize: this.page.pageSize,
          lastId: lastId,
          source: 1
        },
        type: 'GET',
        success: function(res) {
          var list = res.data || [];
          that.lastId = lastId;
          if (list.length < that.page.pageSize) {
            // 判断是否还有下一页，这里粗略处理
            that.page.hasNextPage = false;
          } else {
            that.page.hasNextPage = true;
          }
          if (list.length === 0) {
            $Common.showToast('没有更多数据了');
            return;
          }
          for (var i = 0, len = list.length; i < len; i++) {
            var item = list[i];
            item.updated = $Common.formatDate(item.updated);
          }
          that.mediaReportList = that.mediaReportList.concat(list);
          that.rendered = true;
          setTimeout(function() {
            $('.lazy').lazyload();
          }, 0);
        },
        error: function() {
          $Common.showToast('请求失败，请重试');
        }
      });
    },

    loadMore: function() {
      this.page.pageSize += 1;
      this.getMediaReportList();
    }
  }
});
